package com.example.score.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("t_student_submit")
public class StudentSubmit {
    @TableId(type = IdType.AUTO)
    private Long id;
    private Long examDetailId;
    private Long classId;
    private Long classInfoId;
    private Long studentId;
    private Long studentOmsId;
    private String studentName;
    private String studentNum;
    private String rawStudentNum; //原学生编号
    private Integer submitStatus;
    private Double score;
    private LocalDateTime createdTime;
    private LocalDateTime updatedTime;
    private String paperImages;
    @TableField(exist = false)
    private List<QuestionScore> questionScores;

    @TableField(exist = false)
    private String className;

    // 获取客观题分数
    public double getObjectiveScore() {
        if (questionScores == null || questionScores.isEmpty()) {
            return 0.0;
        }
        return questionScores.stream()
                .filter(qs -> qs.getIsSubjectiveItem() == 0) // 只计算客观题
                .mapToDouble(QuestionScore::getScore)
                .filter(score -> score >= 0)
                .sum();
    }

    // 获取主观题分数
    public double getSubjectiveScore() {
        if (questionScores == null || questionScores.isEmpty()) {
            return 0.0;
        }
        return questionScores.stream()
                .filter(qs -> qs.getIsSubjectiveItem() == 1) // 只计算主观题
                .mapToDouble(QuestionScore::getScore)
                .filter(score -> score >= 0)
                .sum();
    }

    // 获取总分
    public double getScore() {
        return score != null ? score : 0.0;
    }
} 